package serializer

import (
	"singo/model"
	"time"
)

// Mistake 序列化器
type Mistake struct {
	ID        uint   `json:"id"`
	Name      string `json:"name"`
	Info      string `json:"info"`
	Url       string `json:"url"`
	Source    string `json:"source"`
	Status    uint   `json:"status"`
	Ip        string `json:"ip"`
	UserAgent string `json:"user_agent"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

// BuildMistake 序列化
func BuildMistake(item model.Mistake) Mistake {
	return Mistake{
		ID:        item.ID,
		Name:      item.Name,
		Info:      item.Info,
		Source:    item.Source,
		Url:       item.Url,
		Ip:        item.Ip,
		UserAgent: item.UserAgent,
		Status:    item.Status,
		CreatedAt: item.CreatedAt.In(time.Local).Format("2006-01-02 15:04:05"),
		UpdatedAt: item.UpdatedAt.In(time.Local).Format("2006-01-02 15:04:05"),
	}
}

// BuildMistakes 序列化列表
func BuildMistakes(items []model.Mistake) (mistakes []Mistake) {
	for _, item := range items {
		mistake := BuildMistake(item)
		mistakes = append(mistakes, mistake)
	}
	return mistakes
}
